using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Shop : MonoBehaviour
{
    int CurrentMoney;
    List<GameObject> CategoryButtons  = new List<GameObject>();
    List<GameObject> Category = new List<GameObject>();
    void Start()
    {
        CurrentMoney = 100;
        for (int i = 0; i < transform.GetChild(3).childCount; i++) 
        {
            CategoryButtons.Add(transform.GetChild(3).GetChild(i).gameObject);
            Category.Add(transform.GetChild(4).GetChild(i).gameObject);
            Category[i].gameObject.SetActive(false);
            int a = i;
            CategoryButtons[i].GetComponent<Button>().onClick.AddListener(() =>
            {
                ChangeCategory(a);
            });
        }
    }
    void Update()
    {
        transform.GetChild(2).GetChild(0).GetComponent<Text>().text = CurrentMoney.ToString();
    }
    public void ChangeCategory(int index)
    {
        foreach(GameObject g in Category)
        {
            g.gameObject.SetActive(false);
        }
        Category[index].gameObject.SetActive(true);
    }
}
